﻿package hlm.learn;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;

public class MyServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        String method=req.getMethod();
        String username=req.getParameter("username");
        String pwd=req.getParameter("pwd");
        StringBuilder respBody=new StringBuilder();
        respBody.append("");
        String title="";
        if(username.equals("hlm")&&pwd.equals("123")){
            title="登录成功";
            respBody.append("<html>"+"<head>"+"<title>")
                    .append(title).append("</title>"+"</head>");
            respBody.append("<body>");
            respBody.append(username+"登录成功,欢迎回来<br>");
            respBody.append("<//body><//html>");
        }else{
            respBody.append("<b>用户名或密码错误 <//b>");
        }
        resp.setContentLength(respBody.toString().getBytes().length);
        resp.getWriter().write(respBody.toString());



    }
}
